@extends('layout.master')

@section('content-header')
    <h1>Tipe Lokasi</h1>
    <ol class="breadcrumb">
        <li><a href="/"><i class="fa fa-dashboard"></i> Dashboard</a></li>
        <li class="active"><i class="fa fa-th-list"></i> Tipe Lokasi</li>
    </ol>
@stop

@section('content')
<div class="row">
    <div class="col-xs-12">

        <div class="box">
            <div class="box-body table-responsive">
                {{ HTML::decode(link_to_route('tipes.create', '<i class="fa fa-plus-square"></i> Tambah Data', null, array('class'=>'btn btn-primary'))) }}
                <table id="my-table" class="table table-bordered table-striped">
                    <thead>
                        <tr class="center">
                            <th width="10%">#</th>
                            <th>Kode</th>
                            <th>Tipe Lokasi</th>
                            <th width="10%">Action</th>
                        </tr>
                    </thead>
                    <tbody>
                    	<?php $i = 1 ?>
						@foreach ($tipes as $tipe)
	                        <tr>
	                            <td class="center">{{ $i }}</td>
	                            <td>{{ $tipe->kode }}</td>
	                            <td>{{ $tipe->nama }}</td>
	                            <td class="text-center">
	                                <div class="btn-group">
                                        <a href="#" class="btn btn-default btn-detail" data-kode="{{ $tipe->kode }}" data-nama="{{ $tipe->nama }}" data-keterangan="{{ $tipe->keterangan }}"><i class="fa fa-list text-danger" data-toggle="tooltip" data-placement="top" data-original-title="Detail"></i></a>
	                                	{{ HTML::decode(link_to_route('tipes.edit', '<i class="fa fa-pencil text-warning" data-toggle="tooltip" data-placement="top" data-original-title="Edit"></i>', $tipe->id, array('class'=>'btn btn-default btn-edit'))) }}
	                                	<a href="#" class="btn btn-default btn-delete" data-form='{{Form::model($tipe,array('route'=>array('tipes.destroy',$tipe->id),'method'=>'DELETE','class'=>'formDelete'))}}{{Form::close()}}'><i class="fa fa-times text-danger" data-toggle="tooltip" data-placement="top" data-original-title="Delete"></i></a>
	                                </div>
	                            </td>
	                        </tr>
	                        <?php $i++ ?>
						@endforeach
                    </tbody>
                </table>
            </div><!-- /.box-body -->
        </div><!-- /.box -->
    </div>
</div>
@stop

@section('javascript')
<script type="text/javascript">
    $(function() {
       $('#my-table').dataTable({
            "bPaginate": true,
            "bLengthChange": false,
            "bSort": false,
            "bInfo": true,
            "bAutoWidth": false
        });

        $('.btn-delete').click(function(event) {
            event.preventDefault(); 
            formDelete = $(this).data('form');
            bootbox.confirm('Yakin hapus data ini?'+formDelete, function(yes){
                if(yes) {
                    $('.formDelete').submit();
                }
            });
        });

        $('.table-responsive').on('click', '.btn-detail', function(event) {
            event.preventDefault();
            var detail = '<table class="table"><tr><td width="10%">Kode</td><td width="2%">:</td><td>'+$(this).data('kode')+'</td></tr>';
            detail += '<tr><td>Nama</td><td>:</td><td>'+$(this).data('nama')+'</td></tr>';
            detail += '<tr><td>Keterangan</td><td>:</td><td>'+$(this).data('keterangan')+'</td></tr></table>';
            bootbox.dialog({
                message: detail,
                title: 'Detail Lokasi',
                buttons: {
                    main: {
                        label: "OK",
                        className: "btn-primary"
                    }
                }
            });
        });
    });
</script>
@stop